package model;

import enums.ExtensionEnum;
import enums.LanguageEnum;
import j_util.Utiles;

import java.io.Serializable;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * @author Jose Martin Rozanec;
 */
public class Premisa implements Serializable {
    private String[] premisa;//[0]=El,Las,etc.; [1]=firtsTerm; [2]=son,es; [3]=secondTerm
    private boolean checkSFirstTime = true;//todo sacar a constructor
    private boolean originalS = false;
    private ExtensionEnum extension;

    public Premisa(String premisa) {
        analize(premisa);
    }

    public void setCurrentLanguage(LanguageEnum language) {
//        currentLanguage = language;
        analize(toString());
    }

    public String getFirstTerm() {
        return premisa[1];
    }

    public String getSecondTerm() {
        return premisa[3];
    }

    //return true=todo;false=parte;
    /**
     * Remember: A=[T][p];E=[T][T];I=[p][p];O=[p][T]
     *
     * @param first;
     * @return true if [T], false otherwise;
     */
    public boolean getTermExtension(boolean first) {
        switch (getPartsExtension()) {
            case A:
                if (first) {
                    return true;
                } else {
                    return false;
                }
            case E:
                return true;
            case I:
                return false;
            case O:
                if (first) {
                    return false;
                } else {
                    return true;
                }
        }
        return false;
    }

    public ExtensionEnum getPartsExtension() {
        return extension;
    }


    public static boolean isComplete(String premisa) {
        Premisa premisaObject = new Premisa(premisa);
        String[] array = premisaObject.analizeSpanish(premisa);
        if (array.length == 4) {
            if ((array[1] != null) && (array[2] != null) && (array[3] != null)) {
                //(array[0]!=null) se omite por el caso de considerar algun/a tacito.
                return true;
            }
        }
        return false;
    }

    private void analize(String premisaString) {
        premisa = analizeSpanish(premisaString);
        System.out.println(""+extension);
    }

    public String[] analizeSpanish(String premisaString) {
        String[] premisa = new String[4];
        premisaString=premisaString.replace(".","");
        String savePremisa = premisaString;
        analizeSpanish_A(premisaString, premisa);
        analizeSpanish_E(premisaString, premisa);
        analizeSpanish_OI(premisaString, premisa);

        premisaString = premisaString.toLowerCase();
        if (premisa[0] != null) {
            premisaString = premisaString.replace(premisa[0].toLowerCase(), "");
        }

        if (analizarTerminosYNegacion(premisaString, premisa) && extension == ExtensionEnum.I) {
            extension = ExtensionEnum.O;
        }else{
            //todo lo que sigue funciona,
            // todo se deberia ver la parte de los plurales y la actualizacion de la premisa en los fields
//            if(analizarTerminosYNegacion(premisaString, premisa) && extension == ExtensionEnum.A){
//                extension= ExtensionEnum.E;
//                premisa[0]="Ningun";
//                premisa[2]="es";//todo ver como hacer la logica de plurales
//            }
        }
        eliminarEspaciosEnPremisas(premisa);
        premisaString = savePremisa;
        return premisa;
    }

    /**
     * This method analizes Premisa terms and if the premisa contains a negation.
     * If so, it returns a true value.
     *
     * @param terminos
     * @return boolean - negation statement;
     */
    private boolean analizarTerminosYNegacion(String terminos, String[] premisa) {
        String[] array;
        array = terminos.split(" no es una ");
        if (array.length > 1) {
            premisa[1] = array[0];
            premisa[2] = "no es una";
            premisa[3] = array[1];
            return true;
        } else {
            array = terminos.split(" no es un ");
            if (array.length > 1) {
                premisa[1] = array[0];
                premisa[2] = "no es un";
                premisa[3] = array[1];
                return true;
            } else {
                array = terminos.split(" no es ");
                if (array.length > 1) {
                    premisa[1] = array[0];
                    premisa[2] = "no es";
                    premisa[3] = array[1];
                    return true;
                } else {
                    array = terminos.split(" no son ");
                    if (array.length > 1) {
                        premisa[1] = array[0];
                        premisa[2] = "no son";
                        premisa[3] = array[1];
                        return true;
                    } else {
                        array = terminos.split(" es una ");
                        if (array.length > 1) {
                            premisa[1] = array[0];
                            premisa[2] = "es una";
                            premisa[3] = array[1];
                            return false;
                        } else {
                            array = terminos.split(" es un ");
                            if (array.length > 1) {
                                premisa[1] = array[0];
                                premisa[2] = "es un";
                                premisa[3] = array[1];
                                return false;
                            } else {
                                array = terminos.split(" es ");
                                if (array.length > 1) {
                                    premisa[1] = array[0];
                                    premisa[2] = "es";
                                    premisa[3] = array[1];
                                    return false;
                                } else {
                                    array = terminos.split(" son ");
                                    if (array.length > 1) {
                                        premisa[1] = array[0];
                                        premisa[2] = "son";
                                        premisa[3] = array[1];
                                        return false;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return false;
    }

    public String toString() {
        if (premisa != null) {
            if (premisa[0] == null) {
                return premisa[1] + " " + premisa[2] + " " + premisa[3];
            }
            return premisa[0] + " " + premisa[1] + " " + premisa[2] + " " + premisa[3];
        } else {
            return "";
        }
    }

    public void convert(ExtensionEnum extensionEnum) {
        if (checkSFirstTime) {
            checkSFirstTime = false;
            originalS = checkOriginalS(premisa);
        }
        switch (extensionEnum) {
            case A:
                if (getPartsExtension() != ExtensionEnum.A) {
                    if (analizeFemenino()) {//esfemenino
                        if (analizePlural()) {//es plural
                            premisa[0] = "Todas las";
                            premisa[2] = "son";
                            premisa = checkS(premisa, true, originalS);
                        } else {
                            premisa[0] = "Toda";
                            premisa[2] = "es";
                        }
                    } else {
                        if (analizePlural()) {//es plural
                            premisa[0] = "Todos los";
                            premisa[2] = "son";
                            premisa = checkS(premisa, true, originalS);
                        } else {
                            premisa[0] = "Todo";
                            premisa[2] = "es";
                        }
                    }
                }
                break;
            case E:
                if (getPartsExtension() != ExtensionEnum.E) {
                    if (analizeFemenino()) {//esfemenino
                        if (analizePlural()) {//es plural
                            premisa[0] = "Ninguna de las";
                            premisa[2] = "es";
                            premisa = checkS(premisa, false, originalS);
                        } else {
                            premisa[0] = "Ninguna";
                            premisa[2] = "es";
                        }
                    } else {
                        if (analizePlural()) {//es plural
                            premisa[0] = "Ninguno de los";
                            premisa[2] = "es";
                            premisa = checkS(premisa, false, originalS);
                        } else {
                            premisa[0] = "Ningun";
                            premisa[2] = "es";
                        }
                    }
                }
                break;
            case I:
                if (getPartsExtension() != ExtensionEnum.I) {
                    if (analizeFemenino()) {//esfemenino
                        if (analizePlural()) {//es plural
                            premisa[0] = "Algunas";
                            premisa[2] = "son";
                            premisa = checkS(premisa, true, originalS);
                        } else {
                            premisa[0] = "Alguna";
                            premisa[2] = "es";
                        }
                    } else {
                        if (analizePlural()) {//es plural
                            premisa[0] = "Algunos";
                            premisa[2] = "son";
                            premisa = checkS(premisa, true, originalS);
                        } else {
                            premisa[0] = "Algun";
                            premisa[2] = "es";
                        }
                    }
                }
                break;
            case O:
                if (getPartsExtension() != ExtensionEnum.O) {
                    if (analizeFemenino()) {//esfemenino
                        if (analizePlural()) {//es plural
                            premisa[0] = "Algunas";
                            premisa[2] = "no son";
                            premisa = checkS(premisa, true, originalS);
                        } else {
                            premisa[0] = "Alguna";
                            premisa[2] = "no es";
                        }
                    } else {
                        if (analizePlural()) {//es plural
                            premisa[0] = "Algunos";
                            premisa[2] = "no son";
                            premisa = checkS(premisa, true, originalS);
                        } else {
                            premisa[0] = "Algun";
                            premisa[2] = "no es";
                        }
                    }
                }
                break;
        }
        extension = extensionEnum;
    }

    public String getTermsExtensionString() {
//        A=[T][p];E=[T][T];I=[p][p];O=[p][T]
        switch (getPartsExtension()) {
            case A:
                return "[T][p]";
            case E:
                return "[T][T]";
            case I:
                return "[p][p]";
            case O:
                return "[p][T]";
        }
        return "";
    }

    private boolean analizeFemenino() {
        return LexicAnalizer.analizeFemenino(premisa[0], premisa[1]);
    }

    private boolean analizePlural() {
        return LexicAnalizer.analizePlural(premisa[1]);
    }

    private void analizeSpanish_A(String premisaString, String[] premisa) {
        if (premisaString.length() >= 3 && (premisaString.substring(0, 3).equalsIgnoreCase("Los") || premisaString.substring(0, 3).equalsIgnoreCase("Las"))) {
            premisa[0] = premisaString.substring(0, 3);
            extension = ExtensionEnum.A;
        } else {
            if (premisaString.length() >= 9 && (premisaString.substring(0, 9).equalsIgnoreCase("Todas las") || premisaString.substring(0, 9).equalsIgnoreCase("Todos los"))) {
                premisa[0] = premisaString.substring(0, 9);
                extension = ExtensionEnum.A;
            } else {
                if (premisaString.length() >= 5 && (premisaString.substring(0, 5).equalsIgnoreCase("Todas") || premisaString.substring(0, 5).equalsIgnoreCase("Todos"))) {
                    premisa[0] = premisaString.substring(0, 5);
                    extension = ExtensionEnum.A;
                } else {
                    if (premisaString.length() >= 4 && (premisaString.substring(0, 4).equalsIgnoreCase("Toda") || premisaString.substring(0, 4).equalsIgnoreCase("Todo"))) {
                        premisa[0] = premisaString.substring(0, 4);
                        extension = ExtensionEnum.A;
                    }
                }
            }
        }
    }

    private void analizeSpanish_E(String premisaString, String[] premisa) {
        if (premisaString.length() >= 14 && (premisaString.substring(0, 14).equalsIgnoreCase("Ninguno de los") || premisaString.substring(0, 14).equalsIgnoreCase("Ninguna de las"))) {
            premisa[0] = premisaString.substring(0, 14);
            extension = ExtensionEnum.I;
        } else {
            if (premisaString.length() >= 8 && (premisaString.substring(0, 8).equalsIgnoreCase("Ningunos") || premisaString.substring(0, 8).equalsIgnoreCase("Ningunas"))) {
                premisa[0] = premisaString.substring(0, 8);
                extension = ExtensionEnum.E;
            } else {
                if (premisaString.length() >= 7 && (premisaString.substring(0, 7).equalsIgnoreCase("Ninguna") || premisaString.substring(0, 7).equalsIgnoreCase("Ninguno"))) {
                    premisa[0] = premisaString.substring(0, 7);
                    extension = ExtensionEnum.E;
                } else {
                    if (premisaString.length() >= 6 && premisaString.substring(0, 6).equalsIgnoreCase("Ningun")) {
                        premisa[0] = premisaString.substring(0, 6);
                        extension = ExtensionEnum.E;
                    }
                }
            }
        }
    }

    private void analizeSpanish_OI(String premisaString, String[] premisa) {
        if (premisaString.length() >= 14 && (premisaString.substring(0, 14).equalsIgnoreCase("Algunas de las") || premisaString.substring(0, 14).equalsIgnoreCase("Algunas de las"))) {
            premisa[0] = premisaString.substring(0, 14);
            extension = ExtensionEnum.I;
            //precisa desambiguacion posterior para conocer si es I/O. Se desambigua en analizeSpanish

        } else {
            if (premisaString.length() >= 13 && (premisaString.substring(0, 13).equalsIgnoreCase("Alguna de las") || premisaString.substring(0, 13).equalsIgnoreCase("Alguno de los"))) {
                premisa[0] = premisaString.substring(0, 13);
                extension = ExtensionEnum.I;
            } else {
                if (premisaString.length() >= 7 && (premisaString.substring(0, 7).equalsIgnoreCase("Algunas") || premisaString.substring(0, 7).equalsIgnoreCase("Algunos"))) {
                    premisa[0] = premisaString.substring(0, 7);
                    extension = ExtensionEnum.I;
                } else {
                    if (premisaString.length() >= 6 && (premisaString.substring(0, 6).equalsIgnoreCase("Alguna") || premisaString.substring(0, 6).equalsIgnoreCase("Alguno"))) {
                        premisa[0] = premisaString.substring(0, 6);
                        extension = ExtensionEnum.I;
                    } else {
                        if (premisaString.length() >= 5 && premisaString.substring(0, 5).equalsIgnoreCase("Algun")) {
                            premisa[0] = premisaString.substring(0, 5);
                            extension = ExtensionEnum.I;
                        } else {
                            if (extension == null) {
                                extension = ExtensionEnum.A;
                            }
                        }
                    }
                }
            }
        }
    }

    private static void eliminarEspaciosEnPremisas(String[] premisa) {
        if (premisa[1] != null) {
            if (premisa[1].startsWith(" ")) {
                premisa[1] = premisa[1].substring(1, premisa[1].length());
            }
            if (premisa[1].endsWith(" ")) {
                premisa[1] = premisa[1].substring(0, premisa[1].length() - 1);
            }
        }
        if (premisa[3] != null) {
            if (premisa[3].startsWith(" ")) {
                premisa[3] = premisa[3].substring(1, premisa[3].length());
            }
            if (premisa[3].endsWith(" ")) {
                premisa[3] = premisa[3].substring(0, premisa[3].length() - 1);
            }
        }
    }

    private static boolean checkOriginalS(String[] premisa) {
        String temp = premisa[3].toLowerCase();
        if (temp.endsWith("s")) {
            return true;
        }
        return false;
    }

    private static String[] checkS(String[] premisa, boolean addS, boolean originalS) {
        String temp = premisa[3].toLowerCase();
        System.out.println("Premisa[3]=" + premisa[3] + ".");
        if (addS && originalS) {
            premisa[3] = premisa[3] + "s";
        } else {
            if (premisa[3].length() != 1 && premisa[3].endsWith("s")) {
                premisa[3] = premisa[3].substring(0, premisa[3].length() - 1);
            }
        }
        return premisa;
    }

    public String toXML() {
        return openTag() + toString() + closeTag();
    }

    public static Premisa parseXML(String xml) {
        xml = xml.replace(openTag(), "");
        xml = xml.replace(closeTag(), "");
        return new Premisa(xml);
    }

    public static String openTag() {
        return "<premisa>";
    }

    public static String closeTag() {
        return "</premisa>";
    }

    public static Premisa getRandomPremisa() {
        ResourceBundle termsResourceBundle = ResourceBundle.getBundle("dictionary_terms");
        ResourceBundle afirmationsResourceBundle = ResourceBundle.getBundle("dictionary_afirmative");
        int lastResource = getLastResource(termsResourceBundle);
        int random = 0;
        while (random == 0) {
            random = Utiles.getRandomInt(lastResource);
        }
        System.out.println("Random: ." + random);
        String[] firstTerms = termsResourceBundle.getString("" + random).split(",");
        String[] secondTerms = afirmationsResourceBundle.getString("" + random).split(",");
        int first = Utiles.getRandomInt(firstTerms.length);
        int second = 0;
        String afirmacion;
        String nexo = " es ";
        boolean secondRefersToFirstTerms = false;
        boolean fromTermsToAfirmative = true;
        int randomOption = Utiles.getRandomInt(3);
        switch (randomOption) {
            case 2:
                return fromAfirmativeToTerms(termsResourceBundle, afirmationsResourceBundle);
//                fromTermsToAfirmative = false;
//                second = Utiles.getRandomInt(secondTerms.length);
//                if (LexicAnalizer.analizeFemenino(null, secondTerms[second])) {
//                    afirmacion = "Alguna ";
//                } else {
//                    afirmacion = "Algun ";
//                }
//                break;
            case 1: //primero para evitar loop infinito en caso de haber un solo termino en firstTerms...
//                if (LexicAnalizer.analizeFemenino(null, firstTerms[first])) {
//                    afirmacion = "Ninguna ";
//                } else {
//                    afirmacion = "Ningun ";
//                }
//                if (firstTerms.length > 1) {
//                    while (second == first) {
//                        second = Utiles.getRandomInt(firstTerms.length);
//                    }
//                    secondRefersToFirstTerms = true;
//                    break;
//                }
                Premisa premisa = fromTermsToTermsNegation(termsResourceBundle);
                if (premisa != null) {
                    return premisa;
                }
            default:
//                if (LexicAnalizer.analizeFemenino(null, firstTerms[first])) {
//                    afirmacion = "Toda ";
//                } else {
//                    afirmacion = "Todo ";
//                }
//                second = Utiles.getRandomInt(secondTerms.length);
//                break;
                return fromTermsToAfirmative(termsResourceBundle, afirmationsResourceBundle);
        }
//        String premisaString;
//        if (fromTermsToAfirmative) {
//            if (secondRefersToFirstTerms) {
//                premisaString = buildPremisaString(afirmacion, firstTerms[first], nexo, firstTerms[second]);
//            } else {
//                premisaString = buildPremisaString(afirmacion, firstTerms[first], nexo, secondTerms[second]);
//            }
//        } else {
//            premisaString = buildPremisaString(afirmacion, secondTerms[second], nexo, firstTerms[first]);
//        }
//        return new Premisa(premisaString);
    }

    public static Premisa getRandomPremisa(Premisa context) {
        String contextFirstTerm = context.getFirstTerm();
        String contextSecondTerm = context.getSecondTerm();
        ResourceBundle termsResourceBundle = ResourceBundle.getBundle("dictionary_terms");
        ResourceBundle afirmationsResourceBundle = ResourceBundle.getBundle("dictionary_afirmative");
        int lastResource = getLastResource(termsResourceBundle);
        String[] array;
        switch (Utiles.getRandomInt(3)) {
            case 0:
                for (int j = 1; j < lastResource; j++) {
                    array = afirmationsResourceBundle.getString("" + j).split(",");
                    for (int s = 0; s < array.length; s++) {
                        if (contextSecondTerm.equalsIgnoreCase("" + array[s])) {
                            String[] options = termsResourceBundle.getString("" + j).split(",");
                            String selectedTerm = contextFirstTerm;
                            if (options.length > 1) {
                                while (selectedTerm.equalsIgnoreCase(contextFirstTerm)) {
                                    selectedTerm = options[Utiles.getRandomInt(options.length)];
                                }
                            }
                            return buildPremisaI(contextSecondTerm, selectedTerm);
                        }
                    }
                }
            case 1:
                for (int j = 1; j < lastResource; j++) {
                    array = termsResourceBundle.getString("" + j).split(",");
                    for (int s = 0; s < array.length; s++) {
                        if (contextFirstTerm.equalsIgnoreCase("" + array[s])) {
                            String[] options = termsResourceBundle.getString("" + j).split(",");
                            String selectedTerm = contextFirstTerm;
                            if (options.length > 1) {
                                while (selectedTerm.equalsIgnoreCase(contextFirstTerm)) {
                                    selectedTerm = options[Utiles.getRandomInt(options.length)];
                                }
                                if (Utiles.getRandomInt(2) == 1) {
                                    return buildPremisaE(contextFirstTerm, selectedTerm);
                                } else {
                                    return buildPremisaE(selectedTerm, contextFirstTerm);
                                }
                            }
                        }
                    }
                }
            case 2:
                for (int j = 1; j < lastResource; j++) {
                    array = termsResourceBundle.getString("" + j).split(",");
                    for (int s = 0; s < array.length; s++) {
                        if (contextFirstTerm.equalsIgnoreCase("" + array[s])) {
                            String[] options = afirmationsResourceBundle.getString("" + j).split(",");
                            String selectedTerm = contextSecondTerm;
                            if (options.length > 1) {
                                while (selectedTerm.equalsIgnoreCase(contextSecondTerm)) {
                                    selectedTerm = options[Utiles.getRandomInt(options.length)];
                                }
                                return buildPremisaA(contextFirstTerm, selectedTerm);
                            }
                        }
                    }
                }
            default:
                return getRandomPremisa();
        }
    }

    private static Premisa fromAfirmativeToTerms(ResourceBundle termsResourceBundle, ResourceBundle afirmationsResourceBundle) {
        int lastResource = getLastResource(termsResourceBundle);
        int random = 0;
        while (random == 0) {
            random = Utiles.getRandomInt(lastResource);
        }
        String[] firstTerms = afirmationsResourceBundle.getString("" + random).split(",");
        String[] secondTerms = termsResourceBundle.getString("" + random).split(",");
        int first = Utiles.getRandomInt(firstTerms.length);
        int second = Utiles.getRandomInt(secondTerms.length);
        return buildPremisaI(firstTerms[first], secondTerms[second]);
    }

    private static Premisa buildPremisaI(String firstTerm, String secondTerm) {
        String afirmacion;
        String nexo = " es ";
        if (LexicAnalizer.analizeFemenino(null, secondTerm)) {
            afirmacion = "Alguna ";
        } else {
            afirmacion = "Algun ";
        }
        return new Premisa(buildPremisaString(afirmacion, firstTerm, nexo, secondTerm));
    }

    /**
     * Returns null if there are not enought terms in the resource bundle;
     *
     * @return
     */
    private static Premisa fromTermsToTermsNegation(ResourceBundle termsResourceBundle) {
        int lastResource = getLastResource(termsResourceBundle);
        int random = 0;
        while (random == 0) {
            random = Utiles.getRandomInt(lastResource);
        }
        String[] firstTerms = termsResourceBundle.getString("" + random).split(",");
        String[] secondTerms = termsResourceBundle.getString("" + random).split(",");
        int first = Utiles.getRandomInt(firstTerms.length);
        int second = Utiles.getRandomInt(secondTerms.length);
        if (firstTerms.length > 1) {
            while (second == first) {
                second = Utiles.getRandomInt(firstTerms.length);
            }
            return buildPremisaE(firstTerms[first], firstTerms[second]);
        }
        return null;
    }

    private static Premisa buildPremisaE(String firstTerm, String secondTerm) {
        String afirmacion;
        String nexo = " es ";
        if (LexicAnalizer.analizeFemenino(null, firstTerm)) {
            afirmacion = "Ninguna ";
        } else {
            afirmacion = "Ningun ";
        }
        return new Premisa(buildPremisaString(afirmacion, firstTerm, nexo, secondTerm));
    }

    private static Premisa fromTermsToAfirmative(ResourceBundle termsResourceBundle, ResourceBundle afirmationsResourceBundle) {
        int lastResource = getLastResource(termsResourceBundle);
        int random = 0;
        while (random == 0) {
            random = Utiles.getRandomInt(lastResource);
        }
        String[] firstTerms = termsResourceBundle.getString("" + random).split(",");
        String[] secondTerms = afirmationsResourceBundle.getString("" + random).split(",");
        int first = Utiles.getRandomInt(firstTerms.length);
        int second = Utiles.getRandomInt(secondTerms.length);
        return buildPremisaA(firstTerms[first], secondTerms[second]);
    }

    private static Premisa buildPremisaA(String firstTerm, String secondTerm) {
        String afirmacion;
        String nexo = " es ";
        if (LexicAnalizer.analizeFemenino(null, firstTerm)) {
            afirmacion = "Toda ";
        } else {
            afirmacion = "Todo ";
        }
        return new Premisa(buildPremisaString(afirmacion, firstTerm, nexo, secondTerm));
    }

    private static int getLastResource(ResourceBundle bundle) {
        int lastResource = 1;
        boolean lastResourceNotReached = true;
        while (lastResourceNotReached) {
            lastResource++;
            try {
                bundle.getString("" + lastResource);
            } catch (MissingResourceException e) {
                lastResourceNotReached = false;
            }
        }
        return lastResource;
    }

    public static String buildPremisaString(String afirmacion, String firstTerm, String nexo, String secondTerm) {
        if (LexicAnalizer.analizeSignificadoVariaConSexo(firstTerm)) {
            if (afirmacion.endsWith("a ") && Math.random() < 0.5) {
                if (afirmacion.equalsIgnoreCase("alguna ")) {
                    afirmacion = "Algun ";
                } else {
                    afirmacion = "Todo ";
                }
            }
        }
        if (LexicAnalizer.analizeFemenino(null, firstTerm) &&
                !LexicAnalizer.analizeSignificadoVariaConSexo(secondTerm) &&
                !LexicAnalizer.analizeSexoInconvertible(secondTerm)) {
            secondTerm = LexicAnalizer.convertToFemenino(secondTerm);
        }
        return afirmacion + firstTerm + nexo + secondTerm;
    }

    public static void main(String[] args) {
        System.out.println("" + Premisa.getRandomPremisa().toString());
    }
}